package com.px.user.entity;

import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.px.user.model.ActionModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Generated;
import org.hibernate.annotations.GenerationTime;

import javax.persistence.*;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Null;
import java.sql.Timestamp;


@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity(name = "const_t")
@org.hibernate.annotations.Table(appliesTo = "const_t", comment = "常量表")
@Table(indexes = {@Index(name = "code_index", columnList = "code", unique = true)})
public class ConstT {

    @Id
    @ApiModelProperty(value = "主键")
    @NotNull(groups = {ActionModel.Update.class})
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Null(groups = {ActionModel.Insert.class}, message = "删除id字段")
    @Column(unique = true, nullable = false, columnDefinition = "bigint comment '主键'")
    private Long id;

    @NotBlank(groups = {ActionModel.Insert.class})
    @ApiModelProperty(value = "编码(保证唯一)")
    @Column(columnDefinition = "varchar(64) comment '编码'")
    private String code;

    @ApiModelProperty(value = "名称")
    @Column(columnDefinition = "varchar(64) comment '名称'")
    private String name;

    @ApiModelProperty(value = "起始")
    @Column(columnDefinition = "varchar(64) comment '起始'")
    private String start;

    @ApiModelProperty(value = "结束")
    @Column(columnDefinition = "varchar(64) comment '结束'")
    private String end;

    @ApiModelProperty(value = "值")
    @Column(columnDefinition = "varchar(64) comment '值'")
    private String value;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "创建时间", hidden = true)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP comment '创建时间'", insertable = false, updatable = false)
    private Timestamp createTime;

    @Generated(GenerationTime.INSERT)
    @ApiModelProperty(value = "更新时间", hidden = true)
    @JsonProperty(access = JsonProperty.Access.WRITE_ONLY)
    @JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd HH:mm:ss", timezone = "GMT+8")
    @Column(columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP comment '更新时间'", insertable = false, updatable = false)
    private Timestamp updateTime;
}
